<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>编辑车辆</title>
    <link rel="stylesheet" type="text/css" href="../css/login.css">
    <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../js/config.js"></script>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/filter.js"></script>
  </head>
  <body>
  <form class="cars-form" id="carsForm" onsubmit="return formSubmit()">
    <input type="hidden" name="marketId" v-bind:value="marketId">
    <input type="hidden" name="userId" v-bind:value="userId">
    <input type="hidden" name="carId" v-bind:value="res.carId">
    <div class="panel">
      <div class="title">收购信息</div>
      <div class="box">
       <div class="cell-car">
         <label>所属分店</label>
         <select  name="shopId" disabled onchange="changeShopId(this.value)" v-if="shopId">
            <option value="">请选择</option>
            <option v-for="shop in shopList" v-bind:value="shop.shopId" >{{shop.shopName}}</option>
         </select>
         <select  name="shopId" onchange="changeShopId(this.value)" v-else="shopId">
            <option value="">请选择</option>
            <option v-for="shop in shopList" v-bind:value="shop.shopId" >{{shop.shopName}}</option>
         </select>
       </div>
       <div class="cell-car">
         <label>所属区域</label>
         <select v-bind:value="res.region.regionId" name="regionId">
            <option v-for="region in regionList" v-bind:value="region.regionId" >{{region.regionName}}</option>
          </select>
       </div>
       <div>
        <div class="cell-car">
          <label>车架号</label>
          <input type="" name="carVin" v-bind:value="res.carVin" required  pattern="^([0-9A-Z]){17}$">
        </div>
        <div class="cell-car">
           <label>品牌</label>
           <input type=""  v-bind:value="res.brand.brandName"  style="margin-right: 10px;" disabled>
           <input type=""  v-bind:value="res.series.seriesName" style="margin-right: 10px;" disabled>
           <input type="" v-bind:value="res.model.modelName" style="width: 300px;" disabled>

           <input type="hidden" name="brandId" v-bind:value="res.brand.brandId">
           <input type="hidden" name="seriesId" v-bind:value="res.series.seriesId">
           <input type="hidden" name="modelId" v-bind:value="res.model.modelId">
           
         </div>
       </div>
       
       <div class="cell-car">
         <label>表显里程</label>
         <div class="group-input"><input type="" name="carMileage" v-bind:value="res.carMileage" required><span>万公里</span></div>
       </div>
<!--        <div class="cell-car">
         <label>实际里程</label>
         <div class="group-input"><input type="" name="carMileage" v-bind:value="res.carMileage"><span>万公里</span></div>
       </div> -->

       <div class="cell-car">
         <label>钥匙数量</label>
         <div class="group-input"><input type="" name="carKeyNum" v-bind:value="res.carKeyNum" ><span>把</span></div>
       </div>
        <div class="cell-car">
          <label>首次上牌</label>
          <div class="group-radio"><input name="carLicenceState" type="radio" value="1" v-model="res.carLicenceState" />已经上牌</div> 
          <div class="group-radio"><input name="carLicenceState" type="radio" value="2" v-model="res.carLicenceState" />未上牌</div> 
          <div class="group-radio"><input name="carLicenceState" type="radio" value="3" v-model="res.carLicenceState" />新车</div> 
          <input type="month" name="carLicenceDate" v-bind:value="res.carLicenceDate | filterGetDate" :max="nowMonth" :disabled="res.carLicenceState != 1">
        </div>
      </div>
    </div>
    <div class="panel">
      <div class="title">基本信息</div>
      <div class="box">
        <div class="cell-car">
          <label>宣传标题</label>
          <input type="" name="carTitle" v-bind:value="res.carTitle" required>
        </div>
        <div class="cell-car">
          <label><span class="red">*</span>销售人员</label>
          <select v-bind:value="res.saleUserId"  name="saleUserId" required>
            <option value="">请选择</option>
            <option  v-for="user in userList" v-bind:value="user.userId" >{{user.userName}}</option>
          </select>
        </div>
        
        <div class="cell-car">
          <label>车型</label>
          <select v-bind:value="res.carTypeId" name="carTypeId">
            <option  v-for="carType in carTypeList" v-bind:value="carType.carTypeId"  >{{carType.carTypeName}}</option>
          </select>
        </div>
        <div class="cell-car">
          <label>车门数</label>
          <div class="group-input"><input type="" name="carDoorNum" v-bind:value="res.carDoorNum"><span>门</span></div>
        </div>
        <div class="cell-car">
          <label>排气量</label>
          <div class="group-input" id="carDisplacement">
            <input type="text" name="carDisplacement" v-bind:value="res.carDisplacement">
            <input type="text" name="carInletModel" :value="Tchecked?'T':'L'" readonly  id="carInletModelId">
            <!-- <span v-if="Tchecked" style="margin-left:-6px;">T</span><span v-else="Tchecked"  style="margin-left:-6px;">L</span> -->
          </div>
          <div class="group-checkbox" style="margin-left: -20px" ><input  type="checkbox" v-model="Tchecked"  />涡轮增压</div>
        </div>
        <div class="cell-car">
          <label>燃料类型</label>
          <select v-bind:value="res.carFuel" name="carFuel">
            <option>汽油</option>
            <option>柴油</option>
            <option>电动</option>
            <option>混合</option>
            <option>其他</option>
          </select>
        </div>
        <div class="cell-car">
          <label>变速箱</label>
          <select v-bind:value="res.carGearbox" name="carGearbox">
            <option>自动</option>
            <option>手动</option>
          </select>
        </div>
        <div class="cell-car">
          <label>排放标准</label>
          <select v-bind:value="res.carEnviron" name="carEnviron">
            <option value="国I">国I</option>
            <option value="国II">国II</option>
            <option value="国III">国III</option>
            <option value="国IV">国IV</option>
            <option value="国V">国V</option>
            <option value="欧I">欧I</option>
            <option value="欧II">欧II</option>
            <option value="欧III">欧III</option>
            <option value="欧IV">欧IV</option>
            <option value="欧V">欧V</option>
            <option value="欧VI">欧VI</option>
          </select>
        </div>
        <div class="cell-car">
          <label>外观颜色</label>
          <!-- <input type="" name="carOutColor" v-bind:value="res.carOutColor"> -->
          <select v-bind:value="res.carOutColor"  name="carOutColor" required>
            <option>黑色</option>
            <option>白色</option>
            <option>银色</option>
            <option>灰色</option>
            <option>棕色</option>
            <option>香槟色</option>
            <option>红色</option>
            <option>蓝色</option>
            <option>绿色</option>
            <option>紫色</option>
            <option>黄色</option>
            <option>橙色</option>
            <option>金色</option>
            <option>其他</option>
          </select>
        </div>
        <div class="cell-car">
          <label>内饰颜色</label>
          <!-- <input type="" name="carInColor" v-bind:value="res.carInColor"> -->
          <select v-bind:value="res.carInColor" name="carInColor" required>
            <option>黑色</option>
            <option>白色</option>
            <option>米色</option>
            <option>银色</option>
            <option>灰色</option>
            <option>棕色</option>
            <option>香槟色</option>
            <option>红色</option>
            <option>蓝色</option>
            <option>绿色</option>
            <option>紫色</option>
            <option>黄色</option>
            <option>橙色</option>
            <option>金色</option>
            <option>其他</option>
          </select>
        </div>

        <!-- <div class="cell-car">
          <label>交强险</label>
          <div class="group-radio"><input name="Fruit4" type="radio" value="" />有</div> 
          <div class="group-radio"><input name="Fruit4" type="radio" value="" />无</div> 
        </div>

        <div class="cell-car">
          <label>商业险</label>
          <div class="group-radio"><input name="Fruit5" type="radio" value="" />有</div> 
          <div class="group-radio"><input name="Fruit5" type="radio" value="" />无</div> 
        </div> -->
        <div class="cell-car">
          <label>交强险到期日期</label>
          <input type="month" name="carForceInsuranceDate" v-bind:value="res.carForceInsuranceDate | filterGetDate" required>
        </div>
        <div class="cell-car">
          <label>商业险到期日期</label>
          <input type="month" name="carBusinessInsuranceDate" v-bind:value="res.carBusinessInsuranceDate | filterGetDate">
        </div>


        <div class="cell-car">
          <label>年审到期</label>
          <input type="month" name="carValidateDate" v-bind:value="res.carValidateDate | filterGetDate" required>
        </div>

        <div class="cell-car">
          <label>出厂年月</label>
          <input type="month" name="carFacotryDate" v-bind:value="res.carFacotryDate | filterGetDate">
        </div>
      </div>
    </div>
    <div class="panel">
      <div class="title">定价信息</div>
      <div class="box">
        <div class="cell-car">
          <label>零售价</label>
          <div class="group-input"><input type="" name="carRetailPrice" v-bind:value="res.carRetailPrice" required><span>万元</span></div>
        </div>
        <div class="cell-car">
          <label>新车指导价</label>
          <div class="group-input"><input type="" name="carGuidePrice" v-bind:value="res.carGuidePrice"><span>万元</span></div>
        </div>
        <div class="cell-car">
          <label>新车完税价</label>
          <div class="group-input"><input type="" name="carTaxPrice" v-bind:value="res.carTaxPrice"><span>万元</span></div>
        </div>
        <div class="cell-car">
          <label style="margin-left: 25px;">是否包含过户费</label>
          <div class="group-radio"><input name="carTransferState" type="radio" value="1" v-model="res.carTransferState" />有</div> 
          <div class="group-radio"><input name="carTransferState" type="radio" value="0" v-model="res.carTransferState" />无</div> 
        </div>
      </div>
    </div>


    <div class="panel">
      <div class="title">车辆描述</div>
      <div class="box">
        <!-- <div class="cell-car">
          <label style="float: left;">费用情况</label>
          <textarea></textarea>
        </div> -->
        <div class="cell-car">
          <label style="float: left;">瑕疵描述</label>
          <textarea v-bind:value="res.carFlawDesc" name="carFlawDesc" maxlength="500"></textarea>
        </div>
      </div>
    </div>



    <div class="panel">
      <div class="title">销售描述</div>
      <div class="box">
        <div class="cell">
          <div class="cell-car">
            <label>一口价</label>
            <div class="group-radio"><input name="carFixedPriceState" type="radio" value="1" v-model="res.carFixedPriceState" />是</div> 
            <div class="group-radio"><input name="carFixedPriceState" type="radio" value="0" v-model="res.carFixedPriceState" />否</div> 
          </div>
          <div class="cell-car">
            <label>可按揭</label>
            <div class="group-radio"><input name="carMortgageState" type="radio" value="1" v-model="res.carMortgageState" />是</div> 
            <div class="group-radio"><input name="carMortgageState" type="radio" value="0" v-model="res.carMortgageState" />否</div> 
          </div>
          <div class="cell-car">
            <label>特价车</label>
            <div class="group-radio"><input name="carBargainPriceState" type="radio" value="1" v-model="res.carBargainPriceState" />是</div> 
            <div class="group-radio"><input name="carBargainPriceState" type="radio" value="0" v-model="res.carBargainPriceState" />否</div> 
          </div>
          <div class="cell-car">
            <label>认证状态</label>
            <div class="group-radio"><input name="carAuthState" type="radio" value="10" v-model="res.carAuthState" />已认证</div> 
            <div class="group-radio"><input name="carAuthState" type="radio" value="0" v-model="res.carAuthState" />未认证</div> 
          </div>
<!--           <div class="cell-car">
            <label>认证状态</label>
            <div class="group-radio"><input name="carAuthState" type="radio" value="1" v-model="res.carAuthState" />已认证</div> 
            <div class="group-radio"><input name="carAuthState" type="radio" value="0" v-model="res.carAuthState" />未认证</div> 
          </div> -->
        </div>
        
        <!-- <div class="cell-car">
          <label>质保等级</label>
          <select></select>
        </div>
        <div class="cell-car">
          <label>质保费用</label>
          <div class="group-input"><input type="" name=""><span>元</span></div>
        </div> -->


        <div class="cell-car">
          <label  style="float: left;">按揭说明</label>
          <textarea v-bind:value="res.carMortgageDesc" name="carMortgageDesc" maxlength="500"></textarea>
        </div>
        <div class="cell-car">
          <label  style="float: left;">卖点描述</label>
          <textarea v-bind:value="res.carSellingPointDesc" name="carSellingPointDesc" maxlength="500"></textarea>
        </div>
      </div>
    </div>



    <!-- <div class="panel">
      <div class="title">图片管理</div>
      <div class="box clearfix">
        <div class="image-list" v-for="carImage in res.carImages">
          <img v-bind:src="imgUrl + carImage.imageUrl">
          <div class="image-loading"></div>
          <p>{{carImage.imageKey | filterImageName}}</p>
          <input type="file"  accept="image/*" name="" v-bind:data-imageKey="carImage.imageKey" v-bind:data-imageUrl="carImage.imageUrl" v-bind:data-imageSeq="carImage.imageSeq">
        </div>
      </div>
    </div> -->

    <div class="panel">
      <div class="title">图片管理</div>
      <div class="box clearfix">
        <div class="image-list" v-for="(carImage,index) in carImageList">
          <img src="">
          <div class="image-loading"></div>
          <p>{{carImage | filterImageName}}</p>
          <input type="file"  accept="image/jpg,image/jpeg,image/png" name="" :data-imageKey="carImage" v-bind:id="carImage" data-imageUrl="" :data-imageSeq="index+1">
          <span class="delete-img" onclick="removeImg(this)"></span>
        </div>
      </div>
    </div>


    <div class="panel">
      <div class="title">车辆保养</div>
      <div class="box">
        <div class="cell-car">
          <label style="margin-left: 20px">是否4S店定期保养</label>
          <div class="group-radio"><input name="car4sUpkeepState" type="radio" value="1" v-model="res.car4sUpkeepState" />是</div> 
          <div class="group-radio"><input name="car4sUpkeepState" type="radio" value="0" v-model="res.car4sUpkeepState" />否</div> 
        </div>
      </div>
    </div>

    <div class="title">车辆配置</div>
    <div class="panel">
      <div class="title">基本参数</div>
      <div class="box">
        <div class="cell-car">
          <label>厂商</label>
          <input type="" name="" v-bind:value="res.model.modelManufacturer" disabled>
        </div>
        <div class="cell-car">
          <label>级别</label>
          <select disabled>
            <option  v-for="carType in carTypeList" v-bind:value="carType.carTypeId" :selected="carType.carTypeId == res.carTypeId" >{{carType.carTypeName}}</option>
          </select>
        </div>
        <div class="cell-car">
          <label>发动机</label>
          <input type="" name="" v-bind:value="res.model.modelEngineModel" disabled>
        </div>
        <div class="cell-car">
          <label>变速箱</label>
          <input type="" name="" v-bind:value="res.model.modelGearbox" disabled>
        </div>
        <div class="cell-car">
          <label>车身结构</label>
          <input type="" name="" v-bind:value="res.model.modelBodywork" disabled> 
        </div>
      </div>
    </div>

    <div class="panel">
      <div class="title">车身</div>
      <div class="box">
        <div class="cell-car">
          <label>长度</label>
          <div class="group-input"><input type="" name="" v-bind:value="res.model.modelLength" disabled><span>mm</span></div>
        </div>
        <div class="cell-car">
          <label>宽度</label>
          <div class="group-input"><input type="" name="" v-bind:value="res.model.modelWidth" disabled><span>mm</span></div>
        </div>
        <div class="cell-car">
          <label>高度</label>
          <div class="group-input"><input type="" name="" v-bind:value="res.model.modelHeight" disabled><span>mm</span></div>
        </div>
        <div class="cell-car">
          <label>轴距</label>
          <div class="group-input"><input type="" name="" v-bind:value="res.model.modelWheelbase" disabled><span>mm</span></div>
        </div>
        <div class="cell-car">
          <label>车身结构</label>
          <input type="" name="" v-bind:value="res.model.modelBody" disabled>
        </div>
      </div>
    </div>

    <div class="panel">
      <div class="title">发动机</div>
      <div class="box">
        <div class="cell-car">
          <label>发动机型号</label>
          <input type="" name="" v-bind:value="res.model.modelEngineModel" disabled>
        </div>
        <div class="cell-car">
          <label>排量</label>
          <div class="group-input"><input type="" name="" v-bind:value="res.model.modelDisplacement" disabled><span>mL</span></div>
        </div>
        <div class="cell-car">
          <label>进气形式</label>
          <input type="" name="" v-bind:value="res.model.modelInletModel" disabled>
        </div>
        <div class="cell-car">
          <label>气缸排列形式</label>
          <input type="" name="" v-bind:value="res.model.modelCylinderArray" disabled>
        </div>
        <div class="cell-car">
          <label>气缸数</label>
          <div class="group-input"><input type="" name="" v-bind:value="res.model.modelCylinderNum" disabled><span>个</span></div>
          
        </div>
        <div class="cell-car">
          <label>燃料形式</label>
          <input type="" name="" v-bind:value="res.model.modelFuelRoz" disabled>
        </div>
        <div class="cell-car">
          <label>环保标准</label>
          <input type="" name="" v-bind:value="res.model.modelEnviron" disabled>
        </div>
      </div>
    </div>

    <div class="panel">
      <div class="title">变速箱</div>
      <div class="box">
        <div class="cell-car">
          <label>变速箱类型</label>
          <input type="" name="" v-bind:value="res.model.modelGearbox" disabled>
        </div>
        <div class="cell-car">
          <label>挡位个数</label>
          <input type="" name="" v-bind:value="res.model.modelGearNum" disabled>
        </div>
      </div>
    </div>
    <div class="panel" v-for="carConf in carConfList">
      <div class="title">{{carConf.confName}}</div>
      <div class="box">
        <div class="cell-car-check" v-for="childCarConfItem in carConf.childCarConf">
          <div class="group-checkbox"><input type="checkbox" name="carConfIds" v-bind:value="childCarConfItem.confId" :checked="childCarConfItem.selectedState">{{childCarConfItem.confName}}</div>
        </div>
      </div>
    </div>


    <div class="btn-box" style="text-align: center;">
      <button class="submit" type="submit">同步配置</button>
      <div class="cancel"  onclick="cancel()">关闭</div>
    </div>

<!--     <div class="panel">
      <div class="title">亮点配置</div>
      <div class="box">
        <div class="cell-car">
          <label style="float: left;">亮点配置</label>
          <textarea></textarea>
        </div>
      </div>
    </div> -->
    
  </form>
<div class="loading"></div>
  </body>
  <script type="text/javascript">
    var numAjax=0;
  $(document).ajaxSuccess(function(evt, request, settings){  
      numAjax++;
      if (numAjax>=5) {
        $('.loading').hide()
      }
   }); 
  var editCars = new Vue({
    el:'#carsForm',
    data:{
      res:{},
      Tchecked:true,
      carTypeList:[],
      shopList:[],
      regionList:[],
      carConfList:[],
      userList:[],
      marketId:marketId,
      userId:userId,
      shopId:shopId,
      imgUrl:imgUrl,
      carImageList:['vin','right_rear','driving_seat','control_booth','odograph','left_anterior','open_trunk','engine_bay','right_side','tyre','insurance','registration_license','vehicle_license'],
    },
    computed:{
      nowMonth:function(){
        Date.prototype.toLocaleString = function() {
          return this.getFullYear() + "-" + ((this.getMonth()+1 >= 1 && this.getMonth()+1 <= 9) ? "0" + (this.getMonth()+1):this.getMonth()+1)
        };
        var unixTimestamp = new Date() ;
        return unixTimestamp.toLocaleString();
      }
    }
  });
  $.ajax({
    type: "get",      //data 传送数据类型。post 传递
    dataType: 'json',  // 返回数据的数据类型json
    url: defaultUrl+"/controller/getCarById",  // yii 控制器/方法
    cache: false,      
    data: {'carId': carId,'imageViewId':2},  //传送的数据
    error:function(){
       alert("数据传输错误");
    },success: function (data) {
      console.log(data);
      if (data.code != 1) {
        alert('数据请求失败')
        return false
      }

      editCars.res = data.result;
      $('input[type="shopId"]').val(editCars.res.shopId);
      if (editCars.res.carInletModel.indexOf('T') >= 0) {
        this.Tchecked = true;
      }
      
      getUserList(editCars.res.shopId);
      setTimeout(function(){
        setImgList();
      },1000)
      
      getCarConf();



    }
  });
  $.ajax({
      type: "get",      //data 传送数据类型。post 传递
      dataType: 'json',  // 返回数据的数据类型json
      url: defaultUrl+"/controller/getCarTypeList",  // yii 控制器/方法
      cache: false,      
      // data: {tel: tel},  //传送的数据
      error:function(){
         alert("数据传输错误");
      },success: function (data) {
        console.log(data);
         if (data.code != 1) {
          return false
         }
         editCars.carTypeList = data.result;
      }
  });
  $.ajax({
    type: "get",      //data 传送数据类型。post 传递
    dataType: 'json',  // 返回数据的数据类型json
    url: defaultUrl+"/controller/getShopList",  // yii 控制器/方法
    cache: false,      
    data: {'marketId': marketId},  //传送的数据
    error:function(){
       alert("数据传输错误");
    },success: function (data) {
      console.log(data);
       if (data.code != 1) {
        return false
       }
       editCars.shopList = data.result;
       $('input[type="shopId"]').val(editCars.res.shopId);
    }
  });
  $.ajax({
    type: "get",      //data 传送数据类型。post 传递
    dataType: 'json',  // 返回数据的数据类型json
    url: defaultUrl+"/controller/getRegionList",  // yii 控制器/方法
    cache: false,      
    data: {'marketId': marketId},  //传送的数据
    error:function(){
       alert("数据传输错误");
    },success: function (data) {
      console.log(data);
       if (data.code != 1) {
        return false
       }
       editCars.regionList = data.result;
    }
  });
  function getCarConf(){
    $.ajax({
      type: "get",      //data 传送数据类型。post 传递
      dataType: 'json',  // 返回数据的数据类型json
      url: defaultUrl+"/controller/getCarConfById",  // yii 控制器/方法
      cache: false,      
      data: {'carId': editCars.res.carId},  //传送的数据
      error:function(){
         alert("数据传输错误");
      },success: function (data) {
        console.log(data);
         if (data.code != 1) {
          return false
         }
         editCars.carConfList = data.result;
      }
    });
  };
  function formSubmit(){
    $('.loading').show();
    var formData = $('#carsForm').serialize();
    var imagesJson = '&carImageJson=['
    $('.image-list input').each(function(index){
      var imageKey = $(this).attr('data-imageKey')
      var imageUrl = $(this).attr('data-imageUrl')
      var imageSeq = $(this).attr('data-imageSeq')
      var imageJson = '{"imageKey":"'+imageKey+'","imageUrl":"'+imageUrl+'","imageSeq":'+imageSeq+'},';
      imagesJson += imageJson;
    });
    imagesJson += ']';

    var imagesData = encodeURI(imagesJson);
    console.log('formData:'+formData);
    $.ajax({
      type: "get",      //data 传送数据类型。post 传递
      dataType: 'json',  // 返回数据的数据类型json
      url: defaultUrl+"/controller/car/updateCar",  // yii 控制器/方法
      cache: false,  
      data:formData+imagesData,  
      error:function(){
        $('.loading').hide();
         alert("数据传输错误");
      },success: function (data) {
        console.log(data);
         if (data.code != 1) {
          alert(data.msg)
          return false
         }
         $('.loading').hide();
         alert('修改成功！');
         // window.location.href = "list.html"
         // window.history.go(-1);
         // parent.closeTab(editCars.res.carId)
      }
    });
    return false;
  }
  function cancel(){
    // window.history.go(-1);
    parent.closeTab(editCars.res.carId)
  }


  $(document).on('change','.image-list input',function(){
      var pic = $(this)[0].files[0];
      var _this = $(this);
      var dataImageKey =  _this.attr('data-imageKey');
      var _thisImg = $(this).parent('.image-list').find('img');
      var _thisParent = $(this).parent('.image-list').find('.image-loading').show();
      var _thisRemoveBtn = $(this).parent('.image-list').find('.delete-img');
      var fd = new FormData();
      fd.append('uploadFile', pic);
      fd.append('imageKey',dataImageKey);
      fd.append('carId',editCars.res.carId);
      $.ajax({
          url:defaultUrl + "/controller/uploadCarImage",
          type:"post",
          // Form数据
          data: fd,
          dataType: 'json',  // 返回数据的数据类型json
          cache: false,
          contentType: false,
          processData: false,
          success:function(data){
            console.log(data);
            _thisParent.hide();
            if (dataImageKey != 'left_anterior') {
              _thisRemoveBtn.show();
            }
            
            if (data.code != 1) {
              return false
             }
             var reader = new FileReader();  
              reader.onload = function(evt){  
                _thisImg.attr('src',evt.target.result);  
              } 
              reader.readAsDataURL(pic); 

              _this.attr('data-imageUrl',data.result.pathUrl);



          },
          error:function(){
            _thisParent.hide();
            alert('上传失败');
          }
      }); 
  });

  function setImgList(){
    var imgList = editCars.res.carImages;
    // console.log(imgList);
    for (var i = 0; i < imgList.length; i++) {
      $('#'+imgList[i].imageKey+'').attr('data-imageUrl',imgList[i].imageUrl);
      $('#'+imgList[i].imageKey+'').parent('.image-list').find('img').attr('src',imgUrl + imgList[i].imageUrl);
      if (imgList[i].imageKey != 'left_anterior') {
        $('#'+imgList[i].imageKey+'').parent('.image-list').find('.delete-img').show();
      }
      
      
      // console.log($('#'+imgList[i].imageKey+'').length);
      // $('input[data-imageKey='+imgList[i].imageKey+']').attr('data-imageUrl',imgList[i].imageUrl);
      // $('input[data-imageKey='+imgList[i].imageKey+']').parent('.image-list').find('img').attr('src',imgUrl + imgList[i].imageUrl);
    }
  }
  function removeImg(ele){

    // var imgId = $(ele).parent('.image-list').find('input').attr('data-imageId');
    $(ele).parent('.image-list').find('img').attr('src','');
    $(ele).parent('.image-list').find('input').attr('data-imageUrl','');
    // $(ele).parent('.image-list').find('input').attr('data-imageId','');
    $(ele).parent('.image-list').find('input').val('');

    $(ele).hide();
    // if (imgId) {
    //   editCars.deleteCarList.push(imgId);
    // }
  }

  function removeImageList(){

    $.ajax({
      type: "get",      //data 传送数据类型。post 传递
      dataType: 'json',  // 返回数据的数据类型json
      url: defaultUrl+"/controller/carImage/deleteCarImage",  // yii 控制器/方法
      cache: false,  
      data:{
        'imageIds': editCars.deleteCarList
      },  
      error:function(){
        $('.loading').hide();
         alert("数据传输错误");
      },success: function (data) {
        console.log(data);
         if (data.code != 1) {
          return false
         }
         $('.loading').hide();
         alert('图片修改成功！');
      }
    });
  }

  

  function getUserList(val){
    $.ajax({
      type: "get",      //data 传送数据类型。post 传递
      dataType: 'json',  // 返回数据的数据类型json
      url: defaultUrl+"/controller/getUserList",  // yii 控制器/方法
      cache: false,      
      data: {'marketId': marketId,'shopId':val},  //传送的数据
      error:function(){
         alert("数据传输错误");
      },success: function (data) {
        console.log(data);
         if (data.code != 1) {
          return false
         }
         editCars.userList = data.result;
      }
    });
  }

  function changeShopId(val){
    if (val != '') {
      getUserList(val);
    }else{
      editCars.userList = [];
    }
    
  }
  


  </script>

</html>


































